//==================================================================
//  Copyright (C) 2006  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
///
///
///
///
///
//==================================================================

#ifndef SHADOWCASTSHADER_H
#define SHADOWCASTSHADER_H

#include "rendm5d.h"

//==================================================================
///
//==================================================================
class BaseShader
{
public:
	RendDevice			*_RDevice;
	RendM5D::Scene		*_RScenep;
	RendShader			*_VtxShaderp;
	RendShader			*_PixShaderp;
	RendShader::Param	_proj_obj_m_shparam;
	RendShader::Param	_view_obj_m_shparam;

public:
	BaseShader( RendDevice *RDevice, RendM5D::Scene *RScenep,
				const std::string	shader_head_src,
				const std::string	vtx_shader_src,
				const std::string	pix_shader_src ) :
		_RDevice(RDevice),
		_RScenep(RScenep),
		_VtxShaderp(0),
		_PixShaderp(0)
	{
		RendShaderManager	&ShaderManager = _RDevice->_ShaderMng;

		std::string	vtx_code_full = shader_head_src + vtx_shader_src;
		std::string	pix_code_full = shader_head_src + pix_shader_src;

		_VtxShaderp = ShaderManager.CreateVertexShaderFromSource( vtx_code_full.c_str() );
		_proj_obj_m_shparam = _VtxShaderp->AddParam( "proj_obj_m" );
		_view_obj_m_shparam = _VtxShaderp->AddParam( "view_obj_m" );
		_PixShaderp = ShaderManager.CreatePixelShaderFromSource( pix_code_full.c_str() );
	}

	RendShader	*GetVtxShader()
	{
		return _VtxShaderp;
	}

	RendShader *GetPixShader()
	{
		return _PixShaderp;
	}

	RendShader::Param	GetNamedVertexSHParam( const char *param_namep ) const
	{
		return _VtxShaderp->GetParamByName( param_namep );
	}
	RendShader::Param	GetNamedPixelSHParam( const char *param_namep ) const
	{
		return _PixShaderp->GetParamByName( param_namep );
	}
};


//==================================================================
///
//==================================================================
class ShadowCastShader : public BaseShader
{
	RendShader::Param	_lproj_obj_m_shparam;
	RendShader::Param	_depth_tex_shparam;

public:
	ShadowCastShader( RendDevice *RDevice, RendM5D::Scene *RScenep );

	void	SetDepthTexture( TextureBase &tex )
	{
		_RDevice->_ShaderMng.SetTexture( _depth_tex_shparam, &tex );
	}
};


#endif